﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JuCloudy.Framework.Process
{
    public class VirtualProcessBase
    {
        public int vName { get; set; }

        public Action vInitialization;

        public Action vLoaded;

        public Action vSleep;

        public Action vWake;

        public Action vClose;

        private  Dictionary<int, object> storge = new Dictionary<int, object>();
        public  Dictionary<int, object> vStorge
        {
            get { return this.storge; }
            set { this.storge = value; }
        }

        public bool IsSleep
        {
            get { return this._IsSleep; }
        }
        private bool _IsSleep = false;

        public void Sleep()
        {
            Thread t = new Thread(() =>
            {
                Application.Current.RootVisual.Dispatcher.BeginInvoke(() =>
                {
                    this.vSleep.Invoke();
                });
            });
            t.Start();
            while (t.IsAlive)
            {
                continue;
            }
            this._IsSleep = true;
        }

        public void Wake()
        {
            Thread t = new Thread(() =>
            {
                Application.Current.RootVisual.Dispatcher.BeginInvoke(() =>
                {
                    this.vWake.Invoke();
                });
            });
            t.Start();
            while (t.IsAlive)
            {
                continue;
            }
            this._IsSleep = false;
        }
    }
}
